﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using University.Workshop.Business;
using University.Workshop.DataAccess;
using University.Workshop.Model;
using System.Web.Security;

namespace University.Workshop.WebApp
{
    public partial class CancelAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                FormsAuthentication.RedirectToLoginPage();
            }
            PasswordAttemptsManager.Reset();
            User user = UserDataAccess.GetUserByEmail(User.Identity.Name);
            emailTextBox.Text = user.ContactInformation.Email;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            PasswordAttemptsManager.Attempts++;
            try 
            {
                UserCancelAccountManager.CancelUserAccount(emailTextBox.Text, passwordTextBox.Text);
                //messageLabel.Text = "Your Account has been cancelled";
                FormsAuthentication.SignOut();
                Response.Write("<script>alert('You can re-activate your account by signing in again!!!'); window.location.href = 'Login.aspx';</script>");
                //FormsAuthentication.RedirectToLoginPage();
               

            }
            catch(Exception ex)
            {
                messageLabel.Text = ex.Message;
            }
        }
    }
}